package com.xzy.spring.demo.postprocess;

import lombok.Data;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * @author xzy
 * @date 2021-02-09 14:28
 * 说明：借助BeanPostProcess接口，自定义所有Bean的初始化后置处理流程
 */
// @Component
@Data
public class MyBeanPostProcessor implements BeanPostProcessor {

    /**
     * 后置处理：初始化之前
     * {@inheritDoc}
     */
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("-->post process before bean（" + beanName + "） initialization");
        return bean;
    }

    /**
     * 后置处理：初始化之后
     * {@inheritDoc}
     */
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("-->post process after bean（" + beanName + "） initialization");
        return bean;
    }
}
